<?php
echo '<script type="text/javascript">';
require APP . WEBROOT_DIR . DS . "js" . DS . "validate" . DS . "job_add.js";
echo '</script>';
?>
<?php
//imprimo en campos ocultos los datos de todos los peloteros
foreach ($peloteros_full as $pelot) {
    echo $this->Form->input('pelotero_phone_number_' . $pelot['Pelotero']['id'], array('type' => 'hidden', 'value' => $pelot['Pelotero']['phone_number']));
    echo $this->Form->input('pelotero_movil_number_' . $pelot['Pelotero']['id'], array('type' => 'hidden', 'value' => $pelot['Pelotero']['movil_number']));
    echo $this->Form->input('pelotero_address_' . $pelot['Pelotero']['id'], array('type' => 'hidden', 'value' => $pelot['Pelotero']['address']));
}
//imprimo en campos ocultos los datos de los pricetypes_receptions
foreach ($pricetypes_receptions as $reception) {
    echo $this->Form->input('pricetype_reception_client_cost_' . $reception['PricetypesReception']['pricetype_id'], array('type' => 'hidden', 'value' => $reception['PricetypesReception']['client_cost']));
    echo $this->Form->input('pricetype_reception_employee_cost_' . $reception['PricetypesReception']['pricetype_id'], array('type' => 'hidden', 'value' => $reception['PricetypesReception']['employee_cost']));
}
//imprimo en campos ocultos los datos de los pricetypes_services
foreach ($pricetypes_services as $service) {
    echo $this->Form->input('pricetype_service_client_cost_' . $service['PricetypesService']['service_id'] . '_' . $service['PricetypesService']['pricetype_id'], array('type' => 'hidden', 'value' => $service['PricetypesService']['client_cost']));
}
//imprimo en campos ocultos los datos de los pricetypes_shows
foreach ($pricetypes_shows as $show) {
    //si es particular
    if ($show['PricetypesShow']['pricetype_id'] != NULL) {
        echo $this->Form->input('pricetype_show_part_client_cost_' . $show['PricetypesShow']['pricetype_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['client_cost']));
        echo $this->Form->input('pricetype_show_part_client_cost_extra_' . $show['PricetypesShow']['pricetype_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['client_cost_extra']));
        echo $this->Form->input('pricetype_show_part_employee_cost_' . $show['PricetypesShow']['pricetype_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['employee_cost']));
    } else {
        //sino es para un pelotero especifico
        echo $this->Form->input('pricetype_show_pelo_client_cost_' . $show['PricetypesShow']['pelotero_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['client_cost']));
        echo $this->Form->input('pricetype_show_pelo_client_cost_extra_' . $show['PricetypesShow']['pelotero_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['client_cost_extra']));
        echo $this->Form->input('pricetype_show_pelo_employee_cost_' . $show['PricetypesShow']['pelotero_id'], array('type' => 'hidden', 'value' => $show['PricetypesShow']['employee_cost']));
    }
}

//imprimo en campos ocultos los datos de los trajes por default de cada show
foreach ($shows_trajes as $show_id => $show_traje) {
    echo $this->Form->input('show_default_costumes_' . $show_id, array('type' => 'hidden', 'value' => $show_traje['default']));
}
?>
<div class="jobs form">
    <?php echo $this->Form->create('Job', array('id' => 'JobAddForm')); ?>
    <fieldset>
        <legend><?php __('Editar Evento / Cumpleaños'); ?></legend>
        <?php
        echo $this->Form->input('id');
        echo $this->Form->input('type', array('label' => 'Tipo', 'type' => 'select', 'options' => array('birthday' => 'Cumpleaños', 'event' => 'Evento'), 'onchange' => 'mostrar_evento_cumple(); return false;'));
        echo $this->Form->input('pelotero_id', array('label' => 'Particular o Pelotero', 'empty' => 'Particular', 'onchange' => 'mostrar_pelotero(); return false;'));
        echo $this->Form->input('pricetype_id', array('label' => 'Tipo de Precio', 'empty' => 'Seleccione'));
        ?>
        <div class="time_range">
            <?php
            echo $this->Form->input('date_from', array('label' => 'Fecha de Inicio', 'div' => array('class' => 'input text required fecha')));
            ?>
            <div class="left">
                <label>Hora de Inicio</label>
                <?php
                echo $this->Form->input('start_hour', array('label' => false, 'type' => 'select', 'options' => $hours));
                ?>
                <span>:</span>
                <?php
                echo $this->Form->input('start_minute', array('label' => false, 'type' => 'select', 'options' => $minutes));
                ?>
            </div>
            <div class="left">
                <label>Hora de Fin</label>
                <?php
                echo $this->Form->input('finish_hour', array('label' => false, 'type' => 'select', 'options' => $hours));
                ?>
                <span>:</span>
                <?php
                echo $this->Form->input('finish_minute', array('label' => false, 'type' => 'select', 'options' => $minutes));
                ?>
            </div>
        </div>
        <?php
        echo $this->Form->input('address', array('label' => 'Dirección'));
        ?>
        <div id="div_extra_info">
            <?php
            echo $this->Form->input('birthday_name', array('label' => 'Nombre del Cumpleañero/a', 'div' => array('id' => 'div_birthday_name')));
            echo $this->Form->input('event_name', array('label' => 'Nombre del Evento', 'div' => array('id' => 'div_event_name')));
            echo $this->Form->input('birthday_date', array('label' => 'Fecha de Nacimiento', 'type' => 'text', 'div' => array('id' => 'div_birthday_date')));
            echo $this->Form->input('age', array('label' => 'Edad', 'div' => array('id' => 'div_age')));

            //por si es de una anotacion
            $valor_anotation = '';
            if (isset($anotation_id)) {
                $valor_anotation = $anotation_id;
            }
            echo $this->Form->input('anotation_id', array('type' => 'hidden', 'value' => $valor_anotation));
            echo $this->Form->input('phone_number', array('label' => 'Teléfono Fijo'));
            echo $this->Form->input('movil_number', array('label' => 'Teléfono Celular'));
            echo $this->Form->input('email', array('label' => 'Email'));
            echo $this->Form->input('contact_name', array('label' => 'Nombre de Contacto'));
            echo $this->Form->input('count_invited', array('label' => 'Cantidad de Invitados'));
            ?>
            <?php echo $this->Html->link('Ocultar información extra', array(), array('id' => 'link_ocultar', 'onclick' => 'ocultar_extra_info(); return false;')); ?>
        </div>
        <?php echo $this->Html->link('Mostrar información oculta', array(), array('id' => 'link_mostrar', 'onclick' => 'mostrar_extra_info(); return false;')); ?>
        <br/>
        <br/>
        <!-- EMPIEZA PARTE DE RECEPCION -->
        <?php
        echo $this->Form->input('check_reception', array('type' => 'checkbox', 'label' => 'Presentación', 'onchange' => 'mostrar_fieldsets(); return false;'));
        ?>
        <div class="clear"></div>
        <fieldset id="fieldset_reception">
            <legend><?php __('Presentación'); ?></legend>
            <?php
            $cant_trajes = array();
//            $t = 1;
//            foreach ($costumes as $costume_id => $costume_name) {
//                //echo $this->Form->input('JobsCostume.costume_id' . $costume_id, array('label' => $costume_name, 'type' => 'checkbox', 'name' => 'data[JobsCostume][][costume_id]', 'value' => $costume_id, 'hiddenField' => false));
//                $cant_trajes[$t] = $t;
//                $t++;
//            }

            $max_cant_reception = 8;
            for ($t = 1; $t <= $max_cant_reception; $t++) {
                $cant_trajes[$t] = $t;
            }

            //en vez de mostrar una opcion por cada traje, le pongo un máximo de 8
//            echo $this->Form->input('reception_employee_total', array('value' => count($cant_trajes), 'type' => 'hidden'));
            echo $this->Form->input('reception_employee_total', array('value' => $max_cant_reception, 'type' => 'hidden'));
            echo $this->Form->input('reception_employee_count', array('label' => 'Cantidad de Personajes', 'type' => 'select', 'options' => $cant_trajes, 'onchange' => 'mostrar_recepcion_empleados(); return false;'));
            //for ($i = 1; $i <= count($cant_trajes); $i++) {
            for ($i = 1; $i <= $max_cant_reception; $i++) {
                ?>
                <div id="recepcion_empleado_<?php echo $i; ?>" class="employee_cost little">
                    <?php
                    $employee_id = '';
                    $costume_id = '';
                    $employee_cost = '';
                    $employee_paid = 0;
                    if (isset($this->data['JobsReceptionEmployee'][$i])) {
                        $employee_id = $this->data['JobsReceptionEmployee'][$i]['employee_id'];
                        $costume_id = $this->data['JobsReceptionEmployee'][$i]['costume_id'];
                        $employee_cost = $this->data['JobsReceptionEmployee'][$i]['cost'];
                        $employee_paid = $this->data['JobsReceptionEmployee'][$i]['paid'];
                    }
                    echo $this->Form->input('reception_employee_id_' . $i, array('value' => $employee_id, 'label' => 'Nombre y Apellido', 'type' => 'select', 'options' => $employees, 'empty' => 'Seleccione', 'name' => 'data[JobsReceptionEmployee][' . $i . '][employee_id]'));
                    echo $this->Form->input('reception_costume_id_' . $i, array('value' => $costume_id, 'label' => 'Traje', 'type' => 'select', 'options' => $costumes, 'empty' => 'Seleccione', 'name' => 'data[JobsReceptionEmployee][' . $i . '][costume_id]'));
                    echo $this->Form->input('reception_employee_cost_' . $i, array('value' => $employee_cost, 'label' => 'Pago Empleado', 'name' => 'data[JobsReceptionEmployee][' . $i . '][cost]'));
                    echo $this->Form->input('reception_employee_paid_' . $i, array('value' => $employee_paid, 'type' => 'hidden', 'label' => 'Pago Empleado', 'name' => 'data[JobsReceptionEmployee][' . $i . '][paid]'));
                    ?>
                </div>
                <?php
            }
            echo $this->Form->input('reception_client_cost', array('label' => 'Costo Total Presentación', 'type' => 'text', 'div' => array('class' => 'job_subtotal'), 'class' => 'calcular_total'));
            ?>
        </fieldset>
        <!-- TERMINA PARTE DE RECEPCION -->
        <!-- EMPIEZA PARTE DE ANIMACIONES -->
        <?php echo $this->Form->input('check_animation', array('type' => 'checkbox', 'label' => 'Animación', 'onchange' => 'mostrar_fieldsets(); return false;')); ?>
        <div class="clear"></div>
        <fieldset id="fieldset_animation">
            <legend><?php __('Animación'); ?></legend>
            <?php
            //$cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10);
            $cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6);
            echo $this->Form->input('animation_employee_total', array('value' => count($cant_empleados), 'type' => 'hidden'));
            echo $this->Form->input('animation_employee_count', array('label' => 'Cantidad de Empleados', 'type' => 'select', 'options' => $cant_empleados, 'onchange' => 'mostrar_animacion_empleados(); return false;'));
            for ($i = 1; $i <= count($cant_empleados); $i++) {
                $employee_id = '';
                $employee_cost = '';
                $employee_paid = 0;
                if (isset($this->data['JobsAnimationEmployee'][$i])) {
                    $employee_id = $this->data['JobsAnimationEmployee'][$i]['employee_id'];
                    $employee_cost = $this->data['JobsAnimationEmployee'][$i]['cost'];
                    $employee_paid = $this->data['JobsAnimationEmployee'][$i]['paid'];
                }
                ?>
                <div id="animacion_empleado_<?php echo $i; ?>" class="employee_cost">
                    <?php
                    echo $this->Form->input('animation_employee_id_' . $i, array('value' => $employee_id, 'label' => 'Nombre y Apellido', 'type' => 'select', 'options' => $employees, 'empty' => 'Seleccione', 'name' => 'data[JobsAnimationEmployee][' . $i . '][employee_id]'));
                    echo $this->Form->input('animation_employee_cost_' . $i, array('value' => $employee_cost, 'label' => 'Pago Empleado', 'name' => 'data[JobsAnimationEmployee][' . $i . '][cost]'));
                    echo $this->Form->input('animation_employee_paid_' . $i, array('value' => $employee_paid, 'type' => 'hidden', 'name' => 'data[JobsAnimationEmployee][' . $i . '][paid]'));
                    ?>
                </div>
                <?php
            }
            echo $this->Form->input('animation_client_cost', array('label' => 'Costo Total Animación', 'type' => 'text', 'div' => array('class' => 'job_subtotal'), 'class' => 'calcular_total'));
            ?>
        </fieldset>
        <!-- TERMINA PARTE DE ANIMACIONES -->
        <!-- EMPIEZA PARTE DE SHOWS -->
        <?php echo $this->Form->input('check_shows', array('type' => 'checkbox', 'label' => 'Shows', 'onchange' => 'mostrar_fieldsets(); return false;')); ?>
        <div class="clear"></div>
        <fieldset id="fieldset_shows">
            <legend><?php __('Shows'); ?></legend>
            <?php
            $id_shows = '';
            foreach ($shows as $show_id => $show_name) {
                //me fijo si va chequeado o no
                $chequeado = isset($this->data['JobsShow'][$show_id]) ? 'checked' : '';
                echo $this->Form->input('JobsShow.show_id' . $show_id, array('checked' => $chequeado, 'label' => $show_name, 'type' => 'checkbox', 'name' => 'data[JobsShow][][show_id]', 'value' => $show_id, 'hiddenField' => false, 'onchange' => 'mostrar_show(' . $show_id . '); return false;'));
                $id_shows .= $show_id . ',';
            }
            //le saco la ultima coma al $id_shows
            $id_shows = substr($id_shows, 0, -1);
            //ahora lo guardo en un campo oculto
            echo $this->Form->input('show_ids', array('type' => 'hidden', 'value' => $id_shows));
            ?>
            <div class="clear"></div>
            <?php
            //ahora despues de imprimir los checkbox, lo que voy a imprimir es la configuración para cada show
            foreach ($shows as $show_id => $show_name) {
                ?>
                <fieldset id="fieldset_show_<?php echo $show_id; ?>">
                    <legend><?php echo $show_name; ?></legend>
                    <?php
                    //$cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10);
                    $cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6);
                    echo $this->Form->input('show_employee_total_' . $show_id, array('value' => count($cant_empleados), 'type' => 'hidden'));
                    echo $this->Form->input('show_employee_count_' . $show_id, array('label' => 'Cantidad de Empleados', 'type' => 'select', 'options' => $cant_empleados, 'onchange' => 'mostrar_show_empleados(' . $show_id . '); return false;'));
                    for ($i = 1; $i <= count($cant_empleados); $i++) {
                        ?>
                        <div id="show_empleado_<?php echo $show_id; ?>_<?php echo $i; ?>" class="employee_cost little">
                            <?php
                            $employee_id = '';
                            $costume_id = '';
                            $employee_cost = '';
                            $employee_paid = 0;
                            if (isset($this->data['JobsShowEmployee'][$show_id][$i])) {
                                $employee_id = $this->data['JobsShowEmployee'][$show_id][$i]['employee_id'];
                                $costume_id = $this->data['JobsShowEmployee'][$show_id][$i]['costume_id'];
                                $employee_cost = $this->data['JobsShowEmployee'][$show_id][$i]['cost'];
                                $employee_paid = $this->data['JobsShowEmployee'][$show_id][$i]['paid'];
                            }

                            echo $this->Form->input('show_employee_id_' . $show_id . '_' . $i, array('value' => $employee_id, 'label' => 'Nombre y Apellido', 'type' => 'select', 'options' => $employees, 'empty' => 'Seleccione', 'name' => 'data[JobsShowEmployee][' . $show_id . '][' . $i . '][employee_id]'));
                            echo $this->Form->input('show_costume_id_' . $show_id . '_' . $i, array('value' => $costume_id, 'label' => 'Traje', 'type' => 'select', 'options' => $costumes, 'empty' => 'Seleccione', 'name' => 'data[JobsShowEmployee][' . $show_id . '][' . $i . '][costume_id]'));
                            echo $this->Form->input('show_employee_cost_' . $show_id . '_' . $i, array('value' => $employee_cost, 'label' => 'Pago Empleado', 'name' => 'data[JobsShowEmployee][' . $show_id . '][' . $i . '][cost]'));
                            echo $this->Form->input('show_employee_paid_' . $show_id . '_' . $i, array('value' => $employee_paid, 'type' => 'hidden', 'name' => 'data[JobsShowEmployee][' . $show_id . '][' . $i . '][paid]'));
                            ?>
                        </div>
                        <?php
                    }
                    $show_client_cost = isset($this->data['JobsShowEmployee'][$show_id]['client_cost']) ? $this->data['JobsShowEmployee'][$show_id]['client_cost'] : 0;
                    echo $this->Form->input('show_client_cost_' . $show_id, array('value' => $show_client_cost, 'label' => 'Costo Show', 'type' => 'text', 'div' => array('class' => 'job_sub_subtotal'), 'name' => 'data[JobsShowEmployee][' . $show_id . '][client_cost]', 'class' => 'calcular_total'));
                    ?>
                </fieldset>
                <?php
            }
            echo $this->Form->input('shows_client_cost', array('label' => 'Costo Total Shows', 'type' => 'text', 'readonly' => true, 'div' => array('class' => 'job_subtotal'), 'class' => 'calcular_total'));
            ?>
        </fieldset>
        <!-- TERMINA PARTE DE SHOWS -->
        <!-- EMPIEZA PARTE DE SERVICIOS -->
        <?php echo $this->Form->input('check_services', array('type' => 'checkbox', 'label' => 'Otros Servicios', 'onchange' => 'mostrar_fieldsets(); return false;')); ?>
        <div class="clear"></div>
        <fieldset id="fieldset_services">
            <legend><?php __('Otros Servicios'); ?></legend>
            <?php
            $cant_servicios = array();
            $w = 1;
            $id_services = '';
            foreach ($services as $service_id => $service_name) {
                $cant_servicios[$w] = $w;
                $w++;
                $id_services .= $service_id . ',';
            }

            //le saco la ultima coma al $id_shows
            $id_services = substr($id_services, 0, -1);
            //ahora lo guardo en un campo oculto
            echo $this->Form->input('service_ids', array('type' => 'hidden', 'value' => $id_services));

            echo $this->Form->input('service_total', array('value' => count($cant_servicios), 'type' => 'hidden'));
            echo $this->Form->input('service_count', array('label' => 'Cantidad de Servicios', 'type' => 'select', 'options' => $cant_servicios, 'onchange' => 'mostrar_servicios(); return false;'));
            for ($i = 1; $i <= count($cant_servicios); $i++) {
                ?>
                <div id="servicio_<?php echo $i; ?>" class="employee_cost super_little">
                    <?php
                    $service_id = '';
                    $provider_id = '';
                    $price = '';
                    $provider_paid = 0;
                    if (isset($this->data['JobsService'][$i])) {
                        $service_id = $this->data['JobsService'][$i]['service_id'];
                        $provider_id = $this->data['JobsService'][$i]['provider_id'];
                        $price = $this->data['JobsService'][$i]['price'];
                        $cost = $this->data['JobsService'][$i]['cost'];
                        $provider_paid = $this->data['JobsService'][$i]['provider_paid'];
                    }

                    echo $this->Form->input('service_service_id_' . $i, array('value' => $service_id, 'label' => 'Servicio', 'type' => 'select', 'options' => $services, 'empty' => 'Seleccione', 'name' => 'data[JobsService][' . $i . '][service_id]', 'onchange' => 'set_cost_service(' . $i . '); return false;'));
                    echo $this->Form->input('service_provider_id_' . $i, array('value' => $provider_id, 'label' => 'Proveedor', 'type' => 'select', 'options' => $providers, 'empty' => 'Seleccione', 'name' => 'data[JobsService][' . $i . '][provider_id]'));
                    echo $this->Form->input('service_price_' . $i, array('value' => $price, 'label' => 'Precio Proveedor', 'name' => 'data[JobsService][' . $i . '][price]'));
                    echo $this->Form->input('service_cost_' . $i, array('value' => $cost, 'label' => 'Costo a Cliente', 'name' => 'data[JobsService][' . $i . '][cost]', 'class' => 'calcular_total'));
                    echo $this->Form->input('service_provider_paid_' . $i, array('value' => $provider_paid, 'type' => 'hidden', 'name' => 'data[JobsService][' . $i . '][provider_paid]'));
                    ?>
                </div>
                <?php
            }
            echo $this->Form->input('services_client_cost', array('label' => 'Costo Total Servicios', 'type' => 'text', 'readonly' => true, 'div' => array('class' => 'job_subtotal'), 'class' => 'calcular_total'));
            ?>
        </fieldset>
        <!-- TERMINA PARTE DE SERVICIOS -->
        <!-- EMPIEZA PARTE DE OBRAS -->
        <?php echo $this->Form->input('check_productions', array('type' => 'checkbox', 'label' => 'Obras', 'onchange' => 'mostrar_fieldsets(); return false;')); ?>
        <div class="clear"></div>
        <fieldset id="fieldset_productions">
            <legend><?php __('Obras'); ?></legend>
            <?php
            $id_productions = '';
            foreach ($productions as $production_id => $production_name) {
                //me fijo si va chequeado o no
                $chequeado = isset($this->data['JobsProduction'][$production_id]) ? 'checked' : '';
                echo $this->Form->input('JobsProduction.production_id' . $production_id, array('checked' => $chequeado, 'label' => $production_name, 'type' => 'checkbox', 'name' => 'data[JobsProduction][][production_id]', 'value' => $production_id, 'hiddenField' => false, 'onchange' => 'mostrar_production(' . $production_id . '); return false;'));
                $id_productions .= $production_id . ',';
            }
            //le saco la ultima coma al $id_productions
            $id_productions = substr($id_productions, 0, -1);
            //ahora lo guardo en un campo oculto
            echo $this->Form->input('production_ids', array('type' => 'hidden', 'value' => $id_productions));
            ?>
            <div class="clear"></div>
            <?php
            //ahora despues de imprimir los checkbox, lo que voy a imprimir es la configuración para cada show
            foreach ($productions as $production_id => $production_name) {
                ?>
                <fieldset id="fieldset_production_<?php echo $production_id; ?>">
                    <legend><?php echo $production_name; ?></legend>
                    <?php
//                    $cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10);
                    $cant_empleados = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6);
                    echo $this->Form->input('production_employee_total_' . $production_id, array('value' => count($cant_empleados), 'type' => 'hidden'));
                    echo $this->Form->input('production_employee_count_' . $production_id, array('label' => 'Cantidad de Empleados', 'type' => 'select', 'options' => $cant_empleados, 'onchange' => 'mostrar_production_empleados(' . $production_id . '); return false;'));
                    for ($i = 1; $i <= count($cant_empleados); $i++) {
                        ?>
                        <div id="production_empleado_<?php echo $production_id; ?>_<?php echo $i; ?>" class="employee_cost little">
                            <?php
                            $employee_id = '';
                            $costume_id = '';
                            $employee_cost = '';
                            $employee_paid = 0;
                            if (isset($this->data['JobsProductionEmployee'][$production_id][$i])) {
                                $employee_id = $this->data['JobsProductionEmployee'][$production_id][$i]['employee_id'];
                                $costume_id = $this->data['JobsProductionEmployee'][$production_id][$i]['costume_id'];
                                $employee_cost = $this->data['JobsProductionEmployee'][$production_id][$i]['cost'];
                                $employee_paid = $this->data['JobsProductionEmployee'][$production_id][$i]['paid'];
                            }

                            echo $this->Form->input('production_employee_id_' . $production_id . '_' . $i, array('value' => $employee_id, 'label' => 'Nombre y Apellido', 'type' => 'select', 'options' => $employees, 'empty' => 'Seleccione', 'name' => 'data[JobsProductionEmployee][' . $production_id . '][' . $i . '][employee_id]'));
                            echo $this->Form->input('production_costume_id_' . $production_id . '_' . $i, array('value' => $costume_id, 'label' => 'Traje', 'type' => 'select', 'options' => $costumes, 'empty' => 'Seleccione', 'name' => 'data[JobsProductionEmployee][' . $production_id . '][' . $i . '][costume_id]'));
                            echo $this->Form->input('production_employee_cost_' . $production_id . '_' . $i, array('value' => $employee_cost, 'label' => 'Pago Empleado', 'name' => 'data[JobsProductionEmployee][' . $production_id . '][' . $i . '][cost]'));
                            echo $this->Form->input('production_employee_paid_' . $production_id . '_' . $i, array('value' => $employee_paid, 'type' => 'hidden', 'name' => 'data[JobsProductionEmployee][' . $production_id . '][' . $i . '][paid]'));
                            ?>
                        </div>
                        <?php
                    }
                    $production_client_cost = isset($this->data['JobsProductionEmployee'][$production_id]['client_cost']) ? $this->data['JobsProductionEmployee'][$production_id]['client_cost'] : 0;
                    echo $this->Form->input('production_client_cost_' . $production_id, array('value' => $production_client_cost, 'label' => 'Costo Obra', 'type' => 'text', 'div' => array('class' => 'job_sub_subtotal'), 'name' => 'data[JobsProductionEmployee][' . $production_id . '][client_cost]', 'class' => 'calcular_total'));
                    ?>
                </fieldset>
                <?php
            }
            echo $this->Form->input('productions_client_cost', array('label' => 'Costo Total Obras', 'type' => 'text', 'readonly' => true, 'div' => array('class' => 'job_subtotal'), 'class' => 'calcular_total'));
            ?>
        </fieldset>
        <!-- TERMINA PARTE DE OBRAS -->
        <div class="resume_total">
            <p><b>Costo Total</b> = Costo Presentación + Costo Animación + Costo Shows + Costo Servicios + Costos Obras</p>
            <p><b>Costo Total</b> = <span id="job_reception_cost">0</span> + <span id="job_animation_cost">0</span> + <span id="job_shows_cost">0</span> + <span id="job_services_cost">0</span> + <span id="job_productions_cost">0</span></p>
            <p><b>Costo Total</b> = <span id="job_total_cost">0</span></p>
        </div>
        <?php
        if($this->data['Job']['sign'] == ''){
            //si no tiene cargada la seña, entonces se la permito cargar
            echo $this->Form->input('sign', array('label' => 'Seña'));
        }else{
            //en caso de que ya la tenga cargada, solo se la mostramos
            echo 'Seña: $'.$this->data['Job']['sign'];
        }
            
        echo $this->Form->input('description', array('label' => 'Notas', 'type' => 'textarea'));
        ?>
    </fieldset>
    <?php echo $this->Form->end(__('Editar', true)); ?>
</div>
<script type="text/javascript" >
    //cada vez que se modifica un monto, se re calcula el monto final
    $('.calcular_total').bind('keyup', function(){setear_costo_total();});
    var primera_corrida = 1;

    (function($){
        // Date picker
        $("#JobDateFrom").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        // Date picker
        $("#JobDateTo").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        // Date picker
        $("#JobBirthdayDate").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });


        mostrar_evento_cumple();
        mostrar_pelotero();
        mostrar_recepcion_empleados();
        mostrar_animacion_empleados();
        mostrar_fieldsets();
        mostrar_todos_shows_empleados();
        mostrar_servicios();
        mostrar_todos_productions_empleados();
        
        primera_corrida = 0;

    })(jQuery);

    function setear_costo_total(){
        //tomo el costo total por recepcion
        var costo_recepcion = $('#JobReceptionClientCost').val();
        if(costo_recepcion == '' || isNaN(costo_recepcion)){
            costo_recepcion = 0;
        }

        //ahora lo pongo dentro del span
        $('#job_reception_cost').html(costo_recepcion);

        /*********************************************************/

        //tomo el costo total por animación
        var costo_animacion = $('#JobAnimationClientCost').val();
        if(costo_animacion == '' || isNaN(costo_animacion)){
            costo_animacion = 0;
        }

        //ahora lo pongo dentro del span
        $('#job_animation_cost').html(costo_animacion);

        /*********************************************************/

        //tomo los costos de todos los shows
        var costo_shows = 0;
        var ids = $('#JobShowIds').val();
        var res = ids.split(',');

        var show = $('#JobCheckShows').attr('checked') == 'checked'?1:0;
        var show_specific = 0;
        var costo_show_specific = 0;
        var i = 0;
        for(i; i < res.length; i++){
            show_specific = $('#JobsShowShowId'+res[i]).attr('checked') == 'checked'?1:0;
            costo_show_specific = $('#JobShowClientCost'+res[i]).val();
            //ahora para cada uno de los show voy sumando su costo, si y solo si estan chequeados
            if(show == 1 && show_specific == 1 && costo_show_specific != '' && !isNaN(costo_show_specific)){
                costo_shows += parseFloat(costo_show_specific);
            }
        }

        //ahora lo pongo dentro del span
        $('#job_shows_cost').html(parseFloat(costo_shows));

        //ademas lo pongo dentro de input que hace un resumen
        $('#JobShowsClientCost').val(parseFloat(costo_shows));


        /*********************************************************/

        //tomo los costos de todos los servicios
        var costo_servicios = 0;
        var ids = $('#JobServiceIds').val();
        var res = ids.split(',');

        var service = $('#JobCheckServices').attr('checked') == 'checked'?1:0;
        var costo_service_specific = 0;
        var i = 0;
        for(i; i < res.length; i++){
            costo_service_specific = $('#JobServiceCost'+i).val();
            //ahora para cada uno de los show voy sumando su costo, si y solo si estan chequeados
            if(service == 1 && costo_service_specific != '' && !isNaN(costo_service_specific)){
                costo_servicios += parseFloat(costo_service_specific);
            }
        }

        //ahora lo pongo dentro del span
        $('#job_services_cost').html(parseFloat(costo_servicios));

        //ademas lo pongo dentro de input que hace un resumen
        $('#JobServicesClientCost').val(parseFloat(costo_servicios));

        /*********************************************************/

        //tomo los costos de todos las producciones
        var costo_producciones = 0;
        var ids = $('#JobProductionIds').val();
        var res = ids.split(',');

        var production = $('#JobCheckProductions').attr('checked') == 'checked'?1:0;
        var production_specific = 0;
        var costo_production_specific = 0;
        var i = 0;
        for(i; i < res.length; i++){
            production_specific = $('#JobsProductionProductionId'+res[i]).attr('checked') == 'checked'?1:0;
            costo_production_specific = $('#JobProductionClientCost'+res[i]).val();
            //ahora para cada uno de las producciones voy sumando su costo, si y solo si estan chequeados
            if(production == 1 && production_specific == 1 && costo_production_specific != '' && !isNaN(costo_production_specific)){
                costo_producciones += parseFloat(costo_production_specific);
            }
        }

        //ahora lo pongo dentro del span
        $('#job_productions_cost').html(parseFloat(costo_producciones));

        //ademas lo pongo dentro de input que hace un resumen
        $('#JobProductionsClientCost').val(parseFloat(costo_producciones));

        /*********************************************************/

        //ahora seteamos el costo total final
        var costo_total = parseFloat(costo_recepcion) + parseFloat(costo_animacion) + parseFloat(costo_shows) + parseFloat(costo_servicios) + parseFloat(costo_producciones);



        //ahora lo pongo dentro del span
        $('#job_total_cost').html(parseFloat(costo_total));

    }

    function mostrar_evento_cumple(){
        //me fijo si tengo que mostrar los campos para un cumpleaños o para un evento
        var tipo = $('#JobType').val();
        if(tipo == 'birthday'){
            $('#div_event_name').hide();
            $('#div_birthday_name').show();
            $('#div_birthday_date').show();
            $('#div_age').show();
        }else{
            $('#div_event_name').show();
            $('#div_birthday_name').hide();
            $('#div_birthday_date').hide();
            $('#div_age').hide();
        }
    }

    function mostrar_pelotero(){
        //me fijo si tengo que mostrar los campos para un cumpleaños o para un evento
        var pelotero_id = $('#JobPeloteroId').val();
        if(pelotero_id != ''){
            if(primera_corrida == 0){
                //muestro los datos del pelotero y deshabilito los campos
                $('#JobAddress').val($('#pelotero_address_'+pelotero_id).val());
                $('#JobPhoneNumber').val($('#pelotero_phone_number_'+pelotero_id).val());
                $('#JobMovilNumber').val($('#pelotero_movil_number_'+pelotero_id).val());
                $('#JobAddress').attr('readonly',true);
                $('#JobPhoneNumber').attr('readonly',true);
                $('#JobMovilNumber').attr('readonly',true);
            }
            //oculto los datos extra
            ocultar_extra_info();
            
        }else{
            if(primera_corrida == 0){
                //saco los datos del pelotero y habilito los campos
                $('#JobAddress').val('');            
                $('#JobPhoneNumber').val('');            
                $('#JobMovilNumber').val('');            
                $('#JobAddress').attr('readonly',false);
                $('#JobPhoneNumber').attr('readonly',false);
                $('#JobMovilNumber').attr('readonly',false);
            }
            
            //oculto los datos extra
            mostrar_extra_info()
        }

        //actualizco los precios de los shows porque se cambio el pelotero
        mostrar_todos_shows_empleados();
    }
    
    
    function ocultar_extra_info(){
        $('#div_extra_info').slideUp();
        $('#link_mostrar').show();
    }
    
    function mostrar_extra_info(){
        $('#div_extra_info').slideDown();
        $('#link_mostrar').hide();
    }


    function mostrar_recepcion_empleados(){
        //leo la cantidad de usuarios que tiene seteado y solo muestro esa cantidad
        //el resto se los oculto
        var total_empleados = $('#JobReceptionEmployeeTotal').val();
        var cant_empleados = $('#JobReceptionEmployeeCount').val();
        var tipo_precio = $('#JobPricetypeId').val();
        var costo_total_recepcion = 0;

        //a esto me lo puedo traer por ajax en vez de imprimir todo
        var costo_cliente = $('#pricetype_reception_client_cost_'+tipo_precio).val();
        var pago_empleado = $('#pricetype_reception_employee_cost_'+tipo_precio).val();
        var i = 1;
        for(i; i <= total_empleados; i++){
            if(i <= cant_empleados){
                $('#recepcion_empleado_'+i).show();
                //agrego las clases de validacion
                //$('#JobReceptionEmployeeId'+i).addClass('validReceptionEmployeeId');
                $('#JobReceptionCostumeId'+i).addClass('validReceptionCostumeId');
                $('#JobReceptionEmployeeCost'+i).addClass('validReceptionEmployeeCost');

                if(primera_corrida == 0){
                    
                    //si tiene seteado el tipo de precio le precargo el monto
                    if(tipo_precio != ''){
                        //tomo el monto que se le paga al empleado
                        if(costo_cliente != ''){
                            costo_total_recepcion = parseFloat(costo_total_recepcion)+parseFloat(costo_cliente);
                        }
                        $('#JobReceptionEmployeeCost'+i).val(pago_empleado);
                    }
                }

            }else{
                $('#recepcion_empleado_'+i).hide();
                $('#JobReceptionEmployeeId'+i).val('');
                $('#JobReceptionCostumeId'+i).val('');
                $('#JobReceptionEmployeeCost'+i).val('');
                //le saco las clases de validacion
                //$('#JobReceptionEmployeeId'+i).removeClass('validReceptionEmployeeId');
                $('#JobReceptionCostumeId'+i).removeClass('validReceptionCostumeId');
                $('#JobReceptionEmployeeCost'+i).removeClass('validReceptionEmployeeCost');
            }
        }

        if(primera_corrida == 0){
            $('#JobReceptionClientCost').val(costo_total_recepcion);
            //llamo al que re calcula el total
            setear_costo_total();
        }
    }

    function mostrar_servicios(){
        //leo la cantidad de usuarios que tiene seteado y solo muestro esa cantidad
        //el resto se los oculto
        var total_empleados = $('#JobServiceTotal').val();
        var cant_empleados = $('#JobServiceCount').val();
        var i = 1;
        for(i; i <= total_empleados; i++){
            if(i <= cant_empleados){
                $('#servicio_'+i).show();
                //agrego las clases de validacion
                $('#JobServiceServiceId'+i).addClass('validServiceServiceId');
                $('#JobServiceProviderId'+i).addClass('validServiceProviderId');
                $('#JobServicePrice'+i).addClass('validServicePrice');
                $('#JobServiceCost'+i).addClass('validServiceCost');
            }else{
                $('#servicio_'+i).hide();
                $('#JobServiceServiceId'+i).val('');
                $('#JobServiceProviderId'+i).val('');
                $('#JobServicePrice'+i).val('');
                $('#JobServiceCost'+i).val('');
                //le saco las clases de validacion
                $('#JobServiceServiceId'+i).removeClass('validServiceServiceId');
                $('#JobServiceProviderId'+i).removeClass('validServiceProviderId');
                $('#JobServicePrice'+i).removeClass('validServicePrice');
                $('#JobServiceCost'+i).removeClass('validServiceCost');
            }
        }
        //llamo al que re calcula el total
        setear_costo_total();
    }

    function mostrar_animacion_empleados(){
        //leo la cantidad de usuarios que tiene seteado y solo muestro esa cantidad
        //el resto se los oculto
        var total_empleados = $('#JobAnimationEmployeeTotal').val();
        var cant_empleados = $('#JobAnimationEmployeeCount').val();
        var i = 1;
        for(i; i <= total_empleados; i++){
            if(i <= cant_empleados){
                $('#animacion_empleado_'+i).show();
                //agrego las clases de validacion
                //$('#JobAnimationEmployeeId'+i).addClass('validAnimationEmployeeId');
                $('#JobAnimationEmployeeCost'+i).addClass('validAnimationEmployeeCost');
            }else{
                $('#animacion_empleado_'+i).hide();
                $('#JobAnimationEmployeeId'+i).val('');
                $('#JobAnimationEmployeeCost'+i).val('');
                //le saco las clases de validacion
                //$('#JobAnimationEmployeeId'+i).removeClass('validAnimationEmployeeId');
                $('#JobAnimationEmployeeCost'+i).removeClass('validAnimationEmployeeCost');
            }
        }
    }

    function mostrar_fieldsets(){
        var recepcion = $('#JobCheckReception').attr('checked') == 'checked'?1:0;
        var animacion = $('#JobCheckAnimation').attr('checked') == 'checked'?1:0;
        var shows = $('#JobCheckShows').attr('checked') == 'checked'?1:0;
        var services = $('#JobCheckServices').attr('checked') == 'checked'?1:0;
        var productions = $('#JobCheckProductions').attr('checked') == 'checked'?1:0;

        if(recepcion == 1){
            //muestro el fieldset
            $('#fieldset_reception').show();
            //agrego la validacion del costo al cliente
            $('#JobReceptionClientCost').addClass('validReceptionClientCost');
            
            mostrar_recepcion_empleados();
        }else{
            //oculto el fieldset
            $('#fieldset_reception').hide();
            //saco la validacion del costo al cliente
            $('#JobReceptionClientCost').val(0);
            $('#JobReceptionClientCost').removeClass('validReceptionClientCost');
        }

        if(animacion == 1){
            $('#fieldset_animation').show();
            //agrego la validacion del costo al cliente
            $('#JobAnimationClientCost').addClass('validAnimationClientCost');
        }else{
            $('#fieldset_animation').hide();
            //saco la validacion del costo al cliente
            $('#JobAnimationClientCost').val(0);
            $('#JobAnimationClientCost').removeClass('validAnimationClientCost');
        }

        if(shows == 1){
            $('#fieldset_shows').show();
        }else{
            $('#fieldset_shows').hide();
            $('#JobShowsClientCost').val(0);
        }

        if(services == 1){
            $('#fieldset_services').show();
        }else{
            $('#fieldset_services').hide();
            $('#JobServicesClientCost').val(0);
        }

        if(productions == 1){
            $('#fieldset_productions').show();
        }else{
            $('#fieldset_productions').hide();
            $('#JobProductionsClientCost').val(0);
        }

        //llamo al que re calcula el total
        setear_costo_total();
    }

    function mostrar_show(show_id){
        var valor = $('#JobsShowShowId'+show_id).attr('checked') == 'checked'?1:0;
        if(valor == 1){
            //muestro el show
            $('#fieldset_show_'+show_id).show();
            //agrego validacion para que cargue el costo
            $('#JobShowClientCost'+show_id).addClass('validShowClientCost');
            
            if(primera_corrida == 0){
                //reviso cuales son los trajes que usa por default
                var default_costumes =$('#show_default_costumes_'+show_id).val();
                if(default_costumes != ''){
                    var datos = default_costumes.split(',');
                    var cant = datos.length;
                    //seteo la cantidad de empleados
                    $('#JobShowEmployeeCount'+show_id).val(cant);
                
                    //y ahora les voy poniendo cuales son los trajes que tiene que usar
                    var i = 0;
                    for(i; i < cant; i++){
                        $('#JobShowEmployeeId'+show_id+''+(i+1)).val('');
                        $('#JobShowCostumeId'+show_id+''+(i+1)).val(datos[i]);
                        //$('#JobShowEmployeeCost'+show_id+''+(i+1)).val('');
                    }
                }
            }
        }else{
            $('#fieldset_show_'+show_id).hide();
            //saco validacion para que cargue el costo
            $('#JobShowClientCost'+show_id).val('');
            $('#JobShowClientCost'+show_id).removeClass('validShowClientCost');
            
            //lo dejo marcado con dos empleados
            $('#JobShowEmployeeCount'+show_id).val(2);
            for(var i = 1; i <= 6; i++){
                $('#JobShowEmployeeId'+show_id+''+i).val('');
                $('#JobShowCostumeId'+show_id+''+i).val('');
                $('#JobShowEmployeeCost'+show_id+''+i).val('');
            }
        }
        mostrar_show_empleados(show_id);
        //llamo al que re calcula el total
        setear_costo_total();
    }

    function mostrar_show_empleados(show_id){

        var total_empleados = $('#JobShowEmployeeTotal'+show_id).val();
        var cant_empleados = $('#JobShowEmployeeCount'+show_id).val();
        
        var pelotero_id = $('#JobPeloteroId').val();
        var tipo_precio = $('#JobPricetypeId').val();
        
        var client_cost = 0;
        var client_cost_extra = 0;
        var employee_cost = 0;
        
        //primero me fijo si es para un pelotero
        if(pelotero_id != ''){
            client_cost = $('#pricetype_show_pelo_client_cost_'+pelotero_id).val();
            client_cost_extra = $('#pricetype_show_pelo_client_cost_extra_'+pelotero_id).val();
            employee_cost = $('#pricetype_show_pelo_employee_cost_'+pelotero_id).val();
        }else{
            //ahora me fijo que si no es un pelotero, si eligio un tipo de precio
            if(tipo_precio != ''){
                client_cost = $('#pricetype_show_part_client_cost_'+tipo_precio).val();
                client_cost_extra = $('#pricetype_show_part_client_cost_extra_'+tipo_precio).val();
                employee_cost = $('#pricetype_show_part_employee_cost_'+tipo_precio).val();
            }
        }
        
        if(client_cost == ''){
            client_cost = 0;
        }
        if(client_cost_extra == ''){
            client_cost_extra = 0;
        }
        
        if(employee_cost == ''){
            employee_cost = 0;
        }
        
        var i = 1;
        var costo_show = 0;
        for(i; i <= total_empleados; i++){
            if(i <= cant_empleados){
                $('#show_empleado_'+show_id+'_'+i).show();
                //agrego las clases de validacion
                //$('#JobShowEmployeeId'+show_id+''+i).addClass('validShowEmployeeId');
                $('#JobShowCostumeId'+show_id+''+i).addClass('validShowCostumeId');
                $('#JobShowEmployeeCost'+show_id+''+i).addClass('validShowEmployeeCost');
                
                if(primera_corrida == 0){
                    
                    //precargo el pago a empleado
                    $('#JobShowEmployeeCost'+show_id+''+i).val(employee_cost);
                
                    if(i == 1 ){
                        costo_show = parseFloat(client_cost);
                    }
                    if(i > 2){
                        costo_show += parseFloat(client_cost_extra);
                    }
                }
                
            }else{
                $('#show_empleado_'+show_id+'_'+i).hide();
                $('#JobShowEmployeeId'+show_id+''+i).val('');
                $('#JobShowCostumeId'+show_id+''+i).val('');
                $('#JobShowEmployeeCost'+show_id+''+i).val('');
                //le saco las clases de validacion
                $('#JobShowEmployeeId'+show_id+''+i).removeClass('validShowEmployeeId');
                $('#JobShowCostumeId'+show_id+''+i).removeClass('validShowCostumeId');
                $('#JobShowEmployeeCost'+show_id+''+i).removeClass('validShowEmployeeCost');
            }
        }
        
        if(primera_corrida == 0){
            $('#JobShowClientCost'+show_id).val(costo_show);
            setear_costo_total();
        }

    }

    function mostrar_todos_shows_empleados(){
        var ids = $('#JobShowIds').val();
        var res = ids.split(',');

        var i = 0;
        for(i; i < res.length; i++){
            //ahora para cada uno de los show, me fijo si debo mostrar o no
            //su configuración de empleados
            mostrar_show(res[i]);
            mostrar_show_empleados(res[i]);
        }

    }

    function mostrar_production(production_id){
        var valor = $('#JobsProductionProductionId'+production_id).attr('checked') == 'checked'?1:0;
        if(valor == 1){
            $('#fieldset_production_'+production_id).show();
            //agrego validacion para que cargue el costo
            $('#JobProductionClientCost'+production_id).addClass('validProductionClientCost');
        }else{
            $('#fieldset_production_'+production_id).hide();
            //saco validacion para que cargue el costo
            $('#JobProductionClientCost'+production_id).val('');
            $('#JobProductionClientCost'+production_id).removeClass('validProductionClientCost');
        }
        //llamo al que re calcula el total
        setear_costo_total();
    }

    function mostrar_production_empleados(production_id){

        var total_empleados = $('#JobProductionEmployeeTotal'+production_id).val();
        var cant_empleados = $('#JobProductionEmployeeCount'+production_id).val();
        var i = 1;
        for(i; i <= total_empleados; i++){
            if(i <= cant_empleados){
                $('#production_empleado_'+production_id+'_'+i).show();
                //agrego las clases de validacion
                //$('#JobProductionEmployeeId'+production_id+''+i).addClass('validProductionEmployeeId');
                $('#JobProductionCostumeId'+production_id+''+i).addClass('validProductionCostumeId');
                $('#JobProductionEmployeeCost'+production_id+''+i).addClass('validProductionEmployeeCost');
            }else{
                $('#production_empleado_'+production_id+'_'+i).hide();
                $('#JobProductionEmployeeId'+production_id+''+i).val('');
                $('#JobProductionCostumeId'+production_id+''+i).val('');
                $('#JobProductionEmployeeCost'+production_id+''+i).val('');
                //le saco las clases de validacion
                //$('#JobProductionEmployeeId'+production_id+''+i).removeClass('validProductionEmployeeId');
                $('#JobProductionCostumeId'+production_id+''+i).removeClass('validProductionCostumeId');
                $('#JobProductionEmployeeCost'+production_id+''+i).removeClass('validProductionEmployeeCost');
            }
        }

    }

    function mostrar_todos_productions_empleados(){
        var ids = $('#JobProductionIds').val();
        var res = ids.split(',');

        var i = 0;
        for(i; i < res.length; i++){
            //ahora para cada uno de los show, me fijo si debo mostrar o no
            //su configuración de empleados
            mostrar_production(res[i]);
            mostrar_production_empleados(res[i]);
        }

    }
    
    function set_cost_service(id){
        var service = $('#JobServiceServiceId'+id).val();
        var tipo_precio = $('#JobPricetypeId').val();
        var costo = 0;
        //si habia elegido el tipo de precio
        if(tipo_precio != ''){
            
            //si eligio un servicio
            if(service != ''){
                costo = $('#pricetype_service_client_cost_'+service+'_'+tipo_precio).val();
                $('#JobServiceCost'+id).val(costo);
            }else{
                $('#JobServiceCost'+id).val('');
            }
        }
        //llamo al que re calcula el total
        setear_costo_total();
    }

</script>